package com.qinaxiwit.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qianxi.wit.pojo.TbAdministrator;
import com.qianxi.wit.pojo.TbDiagnosticLogout;
import com.qianxi.wit.pojo.TbSufferer;
import com.qinaxiwit.service.impl.TbSuffererService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class TbSuffererController {
    @Autowired
    private TbSuffererService tbSuffererService;

    @GetMapping("/findAllpatient")
    public Page<TbSufferer> findAll(@RequestParam(value = "page") int page,
                                    @RequestParam(value = "pageSize") int pageSize){
        try {
            Page<TbSufferer> list =  tbSuffererService.findAll(page,pageSize);
            return list;
        }catch (Exception e){
            return null;
        }
    }


    @GetMapping("/findAllPatientId")
    public Page<TbDiagnosticLogout> findSufferer(@RequestParam(value = "page") int page,
                                                 @RequestParam(value = "pageSize") int pageSize,
                                                 @RequestParam(value = "id") long id){
        try {
            Page<TbDiagnosticLogout> list =  tbSuffererService.findSufferer(page,pageSize,id);
            return list;
        }catch (Exception e){
            return null;
        }
    }

    @GetMapping("/findbyid/{id}")
    TbDiagnosticLogout findbyid(@PathVariable int id){
        try {

            return tbSuffererService.findbyid(id);
        }catch (Exception e){
            return null;
        }
    }

    @PostMapping("/findByToken")
    TbAdministrator findByToken(@RequestBody TbSufferer tbSufferer){
        try {
            TbAdministrator sufferer = tbSuffererService.findByToken(tbSufferer);
            return sufferer;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    @PostMapping("/deleteByToken")
    void deleteByToken(@RequestBody TbSufferer tbSufferer){
        tbSuffererService.deleteByToken(tbSufferer);
    }

}
